package com.newcapec.modules.pass.controller;

import com.newcapec.common.utils.PageUtils;
import com.newcapec.common.utils.R;
import com.newcapec.modules.pass.entity.PassInfoEntity;
import com.newcapec.modules.pass.service.PassInfoService;
import com.newcapec.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 认证信息表
 *
 * @author steven
 * @email wangsen127@163.com
 * @date 2021-12-26 15:45:53
 */
@RestController
@RequestMapping("pass/passinfo")
public class PassInfoController extends AbstractController {
    @Autowired
    private PassInfoService passInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("pass:passinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = passInfoService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息：废弃
     */
    @Deprecated
    @GetMapping("/info/{id}")
    @RequiresPermissions("pass:passinfo:info")
    public R info(@PathVariable("id") Long id){
		PassInfoEntity passInfo = passInfoService.get(id);

        return R.ok().put("passInfo", passInfo);
    }

    /**
     * 根据学生id查询
     */
    @GetMapping("/get/{studentId}")
    @RequiresPermissions("pass:passinfo:info")
    public R getByStudentId(@PathVariable("studentId") Long studentId){
        PassInfoEntity passInfo = passInfoService.getByStudentId(studentId);

        return R.ok().put("passInfo", passInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("pass:passinfo:save")
    public R save(@RequestBody PassInfoEntity passInfo){
		passInfoService.add(passInfo);

        return R.ok();
    }

    /**
     * 修改：废弃
     */
    @Deprecated
    @PutMapping("/update")
    @RequiresPermissions("pass:passinfo:update")
    public R update(@RequestBody PassInfoEntity passInfo){
		passInfoService.updateById(passInfo);

        return R.ok();
    }

    /**
     * 修改照片
     */
    @PutMapping("/updatePhoto")
    @RequiresPermissions("pass:passinfo:update")
    public R updatePhoto(@RequestBody PassInfoEntity passInfo){
        passInfoService.updatePhoto(passInfo);

        return R.ok();
    }

    /**
     * 生成二维码
     */
    @PutMapping("/generateQrcode")
    @RequiresPermissions("pass:passinfo:update")
    public R generateQrcode(@RequestBody List<Long> ids){
        passInfoService.generateQrcode(ids);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("pass:passinfo:delete")
    public R delete(Long[] ids){
		passInfoService.delete(Arrays.asList(ids));

        return R.ok();
    }
}
